package com.bishi;

import java.util.Scanner;

public class yidong2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        int k = sc.nextInt();
        s = s.replace("[","");
        s = s.replace("]","");
        String[] sarr = s.split(",");
        int[] arr = new int[sarr.length];
        for(int i = 0; i < sarr.length; i++){
            arr[i] = Integer.parseInt(sarr[i]);
        }
        int ans = solution(arr, k);
        System.out.println(ans);
    }

    public static int solution(int[] arr, int k){
        int ans = 0;
        int len = arr.length;
        int i = 0;
        while(i < len){
            if(arr[i] == 1){
                i++;
                continue;
            }
            for(int j = i; j < len && j < i+k; j++){
                if(arr[j] == 0){
                    arr[j] = 1;
                } else if(arr[j] == 1){
                    arr[j] = 0;
                }
            }
            ans++;
            i++;
        }
        for(int m = 0; m < len; m++){
            if(arr[m] == 0){
                return -1;
            }
        }
        return ans;
    }
}
